package io.youngledo.usb.exception;

/// 存储操作异常
///
public class StorageOperationException extends UniversalStorageException {

    public StorageOperationException(ErrorType errorType, String message) {
        super(errorType, message);
    }

    public StorageOperationException(ErrorType errorType, String message, Throwable cause) {
        super(errorType, null, message, cause);
    }

    // 静态工厂方法，用于创建特定类型的异常
    public static StorageOperationException bucketNotFound(String bucketName) {
        return new StorageOperationException(ErrorType.BUCKET_NOT_FOUND,
            "Bucket '" + bucketName + "' not found");
    }

    public static StorageOperationException objectNotFound(String objectKey) {
        return new StorageOperationException(ErrorType.OBJECT_NOT_FOUND,
            "Object '" + objectKey + "' not found");
    }

    public static StorageOperationException accessDenied(String resource) {
        return new StorageOperationException(ErrorType.OBJECT_ACCESS_DENIED,
            "Access denied to resource: " + resource);
    }

    public static StorageOperationException bucketAlreadyExists(String bucketName) {
        return new StorageOperationException(ErrorType.BUCKET_ALREADY_EXISTS,
            "Bucket '" + bucketName + "' already exists");
    }

    public static StorageOperationException unsupportedOperation(String operation) {
        return new StorageOperationException(ErrorType.UNSUPPORTED_OPERATION,
            "Operation '" + operation + "' is not supported");
    }

    public static StorageOperationException operationFailed(String message) {
        return new StorageOperationException(ErrorType.GENERAL, message);
    }

    public static StorageOperationException operationFailed(String message, Throwable cause) {
        return new StorageOperationException(ErrorType.GENERAL, message, cause);
    }
}